package com.aboo.web.common.util;

import org.springframework.aop.TargetSource;
import org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator;
import org.springframework.util.ClassUtils;

public class AnnotationAwareAspectJAutoProxyCreatorExt extends
		AnnotationAwareAspectJAutoProxyCreator {
	private static final long serialVersionUID = -4773502051336538564L;
	private ClassLoader proxyClassLoader = ClassUtils.getDefaultClassLoader();

	protected Object createProxy(Class<?> beanClass, String beanName,
			Object[] specificInterceptors, TargetSource targetSource) {
		boolean proxyTargetClass = this.isProxyTargetClass();
		try {
			Class<?>[] targetInterfaces = ClassUtils.getAllInterfacesForClass(
					beanClass, this.proxyClassLoader);
			if (targetInterfaces != null && targetInterfaces.length != 0) {
				this.setProxyTargetClass(false);
			}
			Object object =super.createProxy(beanClass, beanName, specificInterceptors,
					targetSource);
			return object;
		} finally {
			this.setProxyTargetClass(proxyTargetClass);
		}
	}
}
